import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import ViewUI from 'view-design';
import 'view-design/dist/styles/iview.css';
import './my-theme/index.less';
import moment from 'moment'//导入文件
import preview from 'vue-photo-preview'
import 'vue-photo-preview/dist/skin.css'
Vue.use(preview)
Vue.prototype.$moment = moment;//赋值使用
//  全局过滤器 时间戳 
Vue.filter('dateformat', function (dataStr, pattern = 'YYYY-MM-DD') {
  if (dataStr) {
    return moment.unix(Number(dataStr)).format(pattern)
  } else {
    return dataStr
  }
})
Vue.use(ViewUI, {
  transfer: true,
  size: 'default',
  capture: false,
});
import Clipboard from 'clipboard';
Vue.prototype.Clipboard = Clipboard;
import dataV from '@jiaminghi/data-view'
Vue.use(dataV)
Vue.config.productionTip = false
import mixin from '../src/assets/js/mixin'
Vue.mixin(mixin)
/* 全局路由拦截 */
router.beforeEach((to, from, next) => {
  //iview.LoadingBar.start();
  let token = localStorage.getItem('token')
  if (to.matched.some(record => record.meta.requiresAuth) && (!token || token == 'null')) {
    localStorage.clear();
    next({
      path: '/',
      query: { redirect: to.fullPath }
    })
  } else {
    if(to.path==='/'||to.path==='/permissions'||JSON.parse(localStorage.getItem('operations')).some(e => e.path===to.path)){
      next()
    }else{
      console.log(to)
      next({path: '/permissions'})
    }
    // next()
  };
  if (to.meta.title) {
    document.title = to.meta.title;
  }
})
// router.beforeEach((to, from, next) => {
//   console.log(store.state.token)
//   const operations = store.state.operations;
//   store.dispatch('GenerateRoutes', { operations }).then(() => {
//     router.addRoute(store.state.routers);
//     router.addRoute([{ path: '*', redirect: '/404', hidden: true }]);//最后添加 不然一刷新就会定向到404
//     console.log('router',router)
//   })
//   next()
// })

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
